package org.jeecg.activiti.MyUserInfo;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.activiti.bpmn.converter.BpmnXMLConverter;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.TaskService;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.jeecg.activiti.ActivitClass.SpringContextHolder;
import org.jeecg.activiti.entity.ActReModelFormDeployment;
import org.jeecg.activiti.service.IActReModelFormDeploymentService;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Scanner;

public class UserInfo implements JavaDelegate{


    @Override

    public void execute(DelegateExecution execution) {
//        notify();

        IActReModelFormDeploymentService iActReModelFormDeploymentService= SpringContextHolder.getBean(IActReModelFormDeploymentService.class);
        ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
        System.out.println("executeListener");
        // 任务查询 需要获取一个 TaskService 对象
        String processDefinitionId=execution.getProcessDefinitionId();
        //String processInstanceId=execution.getProcessInstanceId();
        RepositoryService repositoryService=engine.getRepositoryService();
        BpmnModel bpmnModel=repositoryService.getBpmnModel(processDefinitionId);
        System.out.println("bpmnModel" + bpmnModel.getUserTaskFormTypes());

//        BpmnXMLConverter converter = new BpmnXMLConverter();
////        把bpmnModel对象转换成字符
//        byte[] bytes = converter.convertToXML(bpmnModel);
//        String xmlContenxt = bytes.toString();
//        System.out.println("bpmnString" + xmlContenxt);
        QueryWrapper<ActReModelFormDeployment> queryWrapper=new QueryWrapper<ActReModelFormDeployment>()
                .eq("process_Definition_Id", processDefinitionId);
        List<ActReModelFormDeployment> list=iActReModelFormDeploymentService.list(queryWrapper);
        for (ActReModelFormDeployment actReModelFormDeployment : list){
            System.out.println(actReModelFormDeployment.getHtmlJson());
        }



    }
}
